package edu.csumb.itcd.teammario;
import java.awt.*;
import java.util.ArrayList;

/**
 *
 * @author Team Mario
 *
 */
public class Player {
    
    public static int money;
    private boolean playerUp, playerDown, playerLeft, playerRight;
    private int speed;
    private static Point playerPosition;
    private static int currentHealth, maxHealth;
    private int gwidth, gheight;
    private static int width, height;
    private static int shotsFired;
    private static int shotsLanded;
    private static int mouseQuadrant;
    private static double angleToMouse;
    private static int direction = 1;
    private static Poison poisonReceived = new Poison();
    private static ArrayList <Weapon> weaponArray = new ArrayList<Weapon>();
    private static int currentWeaponIndex = 0;
    private static int regDamage;
    private static int regRof;
    private static int poisonDamage = 1;
    private static int poisonDuration = 3;
    private static int poisonRof = 10;
    private static int shotgunDamage = 10;
    private static int shotgunRof = 20;
    
    public static int getWidth() {
        return width;
    }

    public static void setWidth(int width) {
        Player.width = width;
    }

    public static int getHeight() {
        return height;
    }

    public static void setHeight(int height) {
        Player.height = height;
    }

    public Player()
    {
    	maxHealth = 100;
        currentHealth = 100;
        money = 0;
        speed = 1;
        playerPosition = new Point(400,300);
        width = 10;
        height = 10;
        regDamage = 10;
        regRof = 10;
        weaponArray.add(new Weapon(regDamage, regRof));
    }

    public static int getMoney() {
        return money;
    }

    public static void setMoney(int money) {
        Player.money = money;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public static Point getPlayerPosition() {
        return playerPosition;
    }

    public void setPlayerPosition(Point position) {
        playerPosition = position;
    }

    public static int getCurrentHealth() {
    	if (currentHealth <= 0)
    	{
    		currentHealth = 0;
    	}
        return currentHealth;
    }

    public static void setCurrentHealth(int health) {
        currentHealth = health;
    }

    public static int getMaxHealth() {
        return maxHealth;
    }

    public static void setMaxHealth(int health) {
        maxHealth = health;
    }

    public static void setPoisonReceived(Poison poison)
    {
   // 	System.out.print("changing player poison");
    	poisonReceived=poison;
    }

    public static Poison getPoisonReceived() {
		return poisonReceived;
	}

	public static Weapon getCurrentWeapon()
	{
		return weaponArray.get(currentWeaponIndex);
	}
	public static Weapon getWeaponByIndex(int index)
	{
		return weaponArray.get(index);
	}
	public static ArrayList<Weapon> getWeaponArray() {
		return weaponArray;
	}

	public static void addWeapon(Weapon newWeapon)
	{
		weaponArray.add(newWeapon);
	}
    public static void changeWeapon()
    {
    	int temp;
    	temp = currentWeaponIndex;
    	temp ++;
    	if (temp < weaponArray.size())
    	{
    		currentWeaponIndex = temp;
    	}
    	else
    	{
    		currentWeaponIndex = 0;
    	}

    }
    public static int getCurrentWeaponIndex() {
		return currentWeaponIndex;
	}

	public static void setCurrentWeaponIndex(int newWeaponIndex) {
		currentWeaponIndex = newWeaponIndex;
	}
	
	public static boolean hasPoisonWeapon()
	{
		for (int i = 0; i < weaponArray.size(); i++)
		{
			if (weaponArray.get(i).getWeaponName().equals("Poison Weapon"))
			{
				return true;
			}
		}
		return false;
	}
	
	public static PoisonWeapon getPoisonWeapon()
	{
		for (int i = 0; i < weaponArray.size(); i++)
		{
			if (weaponArray.get(i).getWeaponName().equals("Poison Weapon"))
			{
				return (PoisonWeapon)weaponArray.get(i);
			}
		}
		return null;
	}
	
	public static boolean hasShotgunWeapon()
	{
		for (int i = 0; i < weaponArray.size(); i++)
		{
			if (weaponArray.get(i).getWeaponName().equals("Shot Gun Weapon"))
			{
				return true;
			}
		}
		return false;
	}
	
	public static ShotGunWeapon getShotgunWeapon()
	{
		for (int i = 0; i < weaponArray.size(); i++)
		{
			if (weaponArray.get(i).getWeaponName().equals("Shot Gun Weapon"))
			{
				return (ShotGunWeapon)weaponArray.get(i);
			}
		}
		return null;
	}
	
    public static void incrementShotsFired()
    {
    	shotsFired++;
    }
    
    public static int getShotsFired()
    {
    	return shotsFired;
    }
    
    public static void incrementShotsLanded()
    {
    	shotsLanded++;
    }
    
    public static int getShotsLanded()
    {
    	return shotsLanded;
    }
    
    public static double getAccuracy()
    {
    	return (double)shotsLanded/(double)shotsFired;
    }
    
    public void movePlayer()
    {
        if (playerUp == true)
        {
            if (playerPosition.y >= 55 + 3)
            {
                playerPosition.y -= 5+  speed;
            }
        }
        if (playerDown == true)
        {
            if (playerPosition.y <= gheight + height + 20)
            {
                playerPosition.y += 5+  speed;
            }
            
        }
        if (playerLeft == true)
        {
            if (playerPosition.x >= 3)
            {
                playerPosition.x -= 5+ speed;
            }
        }
        if (playerRight == true)
        {
            if (playerPosition.x <= gwidth - width - 10)
            {
                playerPosition.x += 5+ speed;
            }
        }
    }
    
    public int getGwidth() {
        return gwidth;
    }

    public void setGwidth(int gwidth) {
        this.gwidth = gwidth;
    }

    public int getGheight() {
        return gheight;
    }

    public void setGheight(int gheight) {
        this.gheight = gheight;
    }

    public boolean isPlayerUp() {
        return playerUp;
    }

    public void setPlayerUp(boolean playerUp) {
        this.playerUp = playerUp;
    }

    public boolean isPlayerDown() {
        return playerDown;
    }

    public void setPlayerDown(boolean playerDown) {
        this.playerDown = playerDown;
    }

    public boolean isPlayerLeft() {
        return playerLeft;
    }

    public void setPlayerLeft(boolean playerLeft) {
        this.playerLeft = playerLeft;
    }

    public boolean isPlayerRight() {
        return playerRight;
    }

    public void setPlayerRight(boolean playerRight) {
        this.playerRight = playerRight;
    }
    
    public static Rectangle getPlayerImage()
    {
    	return new Rectangle(playerPosition.x, playerPosition.y, width, height);
    }
    
    public void reset()
    {
    	money = 0;
    	playerPosition.setLocation(400, 300);
    	currentHealth = maxHealth;
    	playerUp = false;
    	playerDown = false;
    	playerLeft = false;
    	playerRight = false;
    }

	public static int getRegDamage() {
		return regDamage;
	}

	public static void setRegDamage(int regDamage) {
		Player.regDamage = regDamage;
		Player.getWeaponByIndex(0).setRateOfFire(Player.regDamage);
	}

	public static int getRegRof() {
		return regRof;
	}

	public static void setRegRof(int regRof) {
		Player.regRof = regRof;
		Player.getWeaponByIndex(0).setRateOfFire(Player.regRof);
	}

	public static int getPoisonDamage() {
		return poisonDamage;
	}

	public static void setPoisonDamage(int poisonDamage) {
		Player.poisonDamage = poisonDamage;
		Player.getPoisonWeapon().setDamage(Player.poisonDamage);
	}

	public static int getPoisonDuration() {
		return poisonDuration;
	}

	public static void setPoisonDuration(int poisonDuration) {
		Player.poisonDuration = poisonDuration;
		Player.getPoisonWeapon().setPoisonDuration(Player.poisonDuration);
	}

	public static int getPoisonRof() {
		return poisonRof;
	}

	public static void setPoisonRof(int poisonRof) {
		Player.poisonRof = poisonRof;
		Player.getPoisonWeapon().setRateOfFire(Player.poisonRof);
	}

	public static int getShotgunDamage() {
		return shotgunDamage;
	}

	public static void setShotgunDamage(int shotgunDamage) {
		Player.shotgunDamage = shotgunDamage;
		Player.getShotgunWeapon().setDamage(Player.shotgunDamage);
	}

	public static int getShotgunRof() {
		return shotgunRof;
	}

	public static void setShotgunRof(int shotgunRof) {
		Player.shotgunRof = shotgunRof;
		Player.getShotgunWeapon().setRateOfFire(Player.shotgunRof);
	}
    
}

